#!/usr/bin/python
# -*- coding: utf-8 -*-


from urllib import request
from urllib import parse
import json

# import urllib2
import base64
import time

def post(server_url, params):
    data = parse.urlencode(params).encode('utf-8')
    req = request.Request(server_url, data)
    return json.loads(request.urlopen(req, timeout=10).read())



if __name__ == "__main__":

    start = time.clock()
    # http服务的URL
    url = "http://127.0.0.1:12381/ocr"
    filename = r'C:\Users\he\Desktop\44.png'

    with open(filename, 'rb') as f:
        imgbase64 = base64.b64encode(f.read())

    res = post(url, {"image": imgbase64})
    if res['errcode'] == 200:
        print( ''.join(res['msg']))
    else:
        print('get err')

    stop = time.clock()
    print (stop - start)
